from typing import List
class Solution:
    def findMinMoves(self, machines: List[int]) -> int:
        total=sum(machines)
        n=len(machines)
        if total%n!=0:
            return -1
        step=[0]*n
        ave=total//n
        ans=0
        i=0
        for i in range(n):
            if machines[i]<ave:
                borrow=ave-machines[i]
                machines[i+1]-=borrow
                step[i+1]+=borrow
            elif machines[i]>ave:
                lend=machines[i]-ave
                machines[i+1]+=lend
                step[i]+=lend
            ans=max(ans,step[i])
        return ans


        